|
|
 |
|
|
|
|
If (depth > 1) And is_reflective Then ' Find the view mirror vector VM. vmx = 2 * Nx * VdotN - Vx
vmy = 2 * Ny * VdotN - Vy
vmz = 2 * Nz * VdotN - Vz
' Trace a ray from (px, py, pz) in the
' direction VM. TraceRay False, depth - 1, px, py, pz, _
vmx, vmy, vmz, r_refl, g_refl, b_refl
' Multiply by the reflection coefficients. total_r = total_r + Krr * r_refl
total_g = total_g + Krg * g_refl
total_b = total_b + Krb * b_refl
End If
:
End Sub |
|
|
|
|
|
|
|
|
Figure 17.21 shows program VBRay displaying three spheres over a checkerboard. The middle sphere is green and very reflective. The checkerboard is also very reflective. You can easily see the reflections of all three spheres in the checkerboard and of the outer spheres in the middle sphere. If you look closely, you can see the reflections of the spheres in the checkerboard in the middle sphere, the reflection of the checkerboard off the middle sphere in the checkerboard, and other more complex reflections. The Depth text box in the program was set to 10 in this picture, so rays are traced through no more than 10 reflections. |
|
|
|
|
|
|
|
|
Before examining the code for transparent surfaces, you need to understand some of the physics of light passing through a transparent object. The sections that follow discuss the details you need to know and describe how you can use them to draw transparent objects. |
|
|
|
|
|
|
|
|
Figure 17.21
Three spheres over a reflective checkerboard. |
|
|
|
|
|